package router

import (
	"ginim/docs"
	"ginim/service"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

func Router() *gin.Engine {
	gin.SetMode(gin.ReleaseMode)
	r := gin.Default()

	// swag
	docs.SwaggerInfo.BasePath = ""
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	// 静态资源
	r.Static("/asset", "./web/asset")
	r.LoadHTMLGlob("web/views/**/*")

	r.GET("/", service.Home)
	r.GET("/index", service.Home)
	r.GET("/chat_page", service.ToChat)
	r.GET("/chat", service.Chat)

	// user
	r.GET("/user/list", service.GetUserList)
	r.POST("/user/login", service.FindUserByNameAndPassword)
	r.GET("/user/login_page", service.LoginPage)
	r.GET("/user/register_page", service.RegisterPage)
	r.POST("/user/add", service.CreateUser)
	r.DELETE("/user/delete", service.DeleteUser)
	r.POST("/user/update", service.UpdateUser)
	r.POST("/user/friends", service.FindFriends)
	r.POST("/user/add_friend", service.AddFriend)
	r.GET("/user/send", service.SendUserMsg)
	r.POST("/user/redis_msg", service.RedisMsg)
	r.POST("/user/find", service.FindUserById)

	// message
	r.GET("/message/send", service.SendMsg)

	// attach
	r.POST("/attach/upload", service.Upload)

	// community
	r.POST("/community/create", service.CreateCommunity)
	r.POST("/community/list", service.CommunityList)
	r.POST("/community/join", service.CommunityJoin)

	return r
}
